﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class Helpers
	{
		internal static IGeneratorParser GetGeneratorParser()
		{
			return new GeneratorParser();
		}

		/// <summary>
		/// Checks if the two byte arrays have equal content.
		/// The sequence of bytes is considered, i.e. having the same byte set but a different order results in false
		/// </summary>
		/// <param name="bytes01"></param>
		/// <param name="bytes02"></param>
		/// <returns></returns>
		internal static bool Equals2ByteArrays(byte[] bytes01, byte[] bytes02)
		{
			if ((bytes01 != null) && (bytes02 != null))
			{
				if (bytes01.Length == bytes02.Length)
				{
					for (int index = 0; index < bytes02.Length; index++)
					{
						if (bytes01[index] != bytes02[index])
						{
							return false;
						}
					}

					return true;
				}

				return false;
			}

			// scenario where at least one byte array is null
			if ((bytes01 == null) && (bytes02 == null))
			{
				return true;
			}

			// scenario where only one byte array is null, we consider null and Length==0 to be equal
			if (bytes01 == null)
			{
				return (bytes02.Length == 0);
			}

			return (bytes01.Length == 0);
		}		
	}
}
